@extends('Share/home')
<?php
$title='公司合同管理';
$nav_t='系统管理';
$nav_m='公司合同管理';
?>
@section('demand-body')
<style>
.cContract-box{
   width: 1280px;
   background: #f6f6f6;
   border-top: 2px solid #b2cff0;
   border-bottom: 1px solid #b2cff0;
   margin: 0 auto;
   font-size: 14px;
}
 
/* 合同名字以及有效时间开始@dongdong */
.cContract-box-nametime{
   margin: 32px 0 16px 90px;
   overflow: hidden;
}
.cContract-nametime-name{
   overflow: hidden;
   float: left;
}
.cContract-name-p{
   float: left;
   color: #292929;
   line-height: 30px;
}
.cContract-name-text{
   margin-left: 24px;
   border: 1px solid #c9c9c9;
   width: 178px;
   height: 30px;    overflow: hidden;
   font-size: 14px;
}
.cContract-nametime-time{
   overflow: hidden;
   float: left;
   margin-left: 70px;
}
.cContract-time-p{
   float: left;
   font-size: 14px;
   color: #292929;
   line-height: 30px;
}
.cContract-time-start{
   float: left;
   width: 126px;
   height: 30px;
   border: 1px solid #c9c9c9;
   margin-left: 10px;
}
.cContract-time-conn{
   float: left;
   margin: 7px 10px 0 10px;
   font-weight: bold;
}
.cContract-time-end{
   float: left;
   width: 126px;
   height: 30px;
   border: 1px solid #c9c9c9;
}
/* 合同名字以及有效时间结束@dongdong */
 
/* 合同详情开始@dongdong */
.cContract-box-item{
   width: 1170px;
   margin-left: 110px;
}
.J_cContract_ubox{
   
}
.cContract-item-list{
   display: table;
   overflow: hidden;
   margin-bottom: 16px;
}
.cContract-list-info{
   display: table-cell;
   vertical-align: middle;
}
.cContract-list-index{
   width: 41px;
}
.cContract-index-p{
   width: 41px;
}
.cContract-list-indexc{
   width: 84px;
}
.cContract-index-up{
   margin-left: 5px;
   width: 25px;
   height: 25px;
   float: left;
   background: url('../../img/cContract-up.png') center top no-repeat;
   background-size: 100% 100%;
   cursor: pointer;
}
.cContract-index-down{
   margin-left: 15px;
   width: 25px;
   height: 25px;
   float: left;
   background: url('../../img/cContract-down.png') center top no-repeat;
   background-size: 100% 100%;
   cursor: pointer;
}
.cContract-index-updown:hover{
   text-decoration: none;
}
.cContract-list-job{
   width: 41px;
}
.cContract-job-p{
   width: 41px;
}
.cContract-list-jobc{
   width: 111px;
}
.cContract-jobc-sel{    
   width: 70px;
   height: 30px;
   border: 1px solid #c9c9c9;
}
.cContract-list-demand{
   width: 68px;
}
.cContract-demand-p{
   width: 68px;
}
.cContract-list-demandc{
   width: 218px;
}
.cContract-demandc-input{
   width: 178px;
   border: 1px solid #c9c9c9;
}
.cContract-list-workTime{
   width: 39px;
}
.cContract-workTime-p{
   width: 39px;
}
.cContract-list-workTimec{
   width: 110px;
}
.cContract-workTimec-text{
   width: 58px;
   border: 1px solid #c9c9c9;
}
.cContract-list-demandprice{
   width: 66px;
}
.cContract-demandprice-p{
   width: 66px;
}
.cContract-list-demandpricec{
   width: 144px;
}
.cContract-demandpricec-text{
   width: 86px;
   border: 1px solid #c9c9c9;
}
.cContract-list-wageprice{
   width: 66px;
}
.cContract-wageprice-p{
   width: 66px;
}
.cContract-list-wagepricec{
   width: 115px;        
}
.cContract-wagepricec-text{
   width: 86px;
   border: 1px solid #c9c9c9;
}
/*选择套餐*/
.cContract-item-special{
   display: table;
   overflow: hidden;
   margin-left: 561px;
   margin-bottom: 16px;
}
.cContract-special-webtime{
   width: 39px;
}
.cContract-webtime-p{
   width: 39px;
}
.cContract-special-webtimec{
   width: 110px;
}
.cContract-webtimec-text{
   width: 58px;
   border: 1px solid #c9c9c9;
}
.cContract-special-webprice{
   width: 66px;
}
.cContract-webprice-p{
   width: 66px;
}
.cContract-special-webpricec{
   width: 144px;
}
.cContract-webpricec-text{
   width: 86px;
   border: 1px solid #c9c9c9;
}
.cContract-special-webwage{
   width: 66px;
}
.cContract-webwage-p{
   width: 66px;
}
.cContract-special-webwagec{
   width: 115px;
}
.cContract-webwagec-text{
   width: 86px;
   border: 1px solid #c9c9c9;
}
.cContract-list-stop{
   display: none;
   color: #65beee;
   cursor: pointer;
   vertical-align: middle;
   cursor: pointer;
}
.cContract-list-move{
   cursor: pointer;
   vertical-align: middle;
   cursor: pointer;
}
/* 合同详情结束@dongdong */
 
/* 添加新合同类型开始@dongdong */
.cContract-item-add{
   border: 1px solid #c9c9c9;
   width: 800px;
   height: 30px;
   overflow: hidden;
   margin-left: 110px;
}
.cContract-add-new{
   color: #525252;
   font-size: 14px;
   line-height: 30px;
   cursor: pointer;
   padding-left: 20px;
}
.cContract-new-plus{
   color: #00a7ea;
   font-size: 10px;
   font-weight: bold;
   padding-right: 5px;
}
.cContract-item-submit{
   width: 96px;
   height: 32px;
   color: #fff;
   background: #00a7ea;
   font-size: 16px;
   border: none;
   cursor:pointer;
   margin: 32px 0 32px 140px;
}
.cContract-item-stopB{
   width: 96px;
   height: 32px;
   color: #fff;
   background: #00a7ea;
   font-size: 16px;
   border: none;
   cursor:pointer;
   margin: 32px 0 32px 30px;
}
/* 添加新合同类型结束@dongdong */
 
/* 合同列表开始@dongdong */
.cContract-list-wrap{
   margin-top: 32px;
   
}
.cContract-list-box{
   width: 1280px;
   background: #f6f6f6;
   margin: 0 auto;
   font-size: 14px;
   overflow: hidden;
}
.cContract-box-conword{
   width: 34px;
   height: 16px;
   margin-top: 44px;
   margin-left: 24px;
   float: left;
}
.cContract-box-list{
   overflow: hidden;
   width: 1100px;
   margin-left: 78px;
   padding-top: 32px;
}
.cContract-list-item{
   padding: 0 20px;
   height: 40px;
   background: #e5e5e5;
   float: left;
   margin-right: 36px;
   margin-bottom: 24px;
   text-align: center;
   line-height: 40px;
   cursor: pointer;
}
.cContract-list-item:hover{
   background: #00b5fe;
   color: #fff;
}
.ccContract-list-cur{
   background: #00a7ea;
   color: #fff;
}
.cContract-list-modify{
   width: 96px;
   height: 32px;
   background: #00a7ea;
   border: none;
   color: #fff;
   cursor:pointer;
   font-size: 16px;
   margin-top: 8px;
   margin-left: 78px;
}
/* 合同列表结束@dongdong */
 /* 弹窗开始 */
 .cContract-popup-content{
 	padding-top: 130px;
    padding-bottom: 40px;
    text-align: center;
 }
 .cContract-content-text{
 	border: 1px solid #c9c9c9;
    width: 178px;
    height: 30px;
    overflow: hidden;
    font-size: 14px;
 }
 /* 弹窗开始 */
</style>
 
<div class="demand-body">
<form id='J_cContract_form' action="/system/cContract/create" method="post">
   <input class="J_cContract_form" type="hidden" name="data" value="">
   <input class="J_cContract_pid" type="hidden" name="pact_id" value="">
   <input class="token" name="_token" type="hidden" value="{{csrf_token()}}">
   <div class="cContract-box J_cContract_box">
        <div class="cContract-box-nametime J_cContract_nametime">
            <div class="cContract-nametime-name"><!-- 合同名字 -->
               <p class="cContract-name-p">合同:</p>
               <input type="text" maxlength="17" class="cContract-name-text J_cContract_name" />
            </div>
            <div class="cContract-nametime-time"><!-- 有效期 -->
               <p class="cContract-time-p">有效期:</p>
               <input class="cContract-time-start J_time_start J_cContract_date" type="text" value="">
               <p class="cContract-time-conn">-</p>
               <input class="cContract-time-end J_time_end J_cContract_date" type="text" value="">
            </div>
        </div>
       
        <div class="cContract-box-item J_cContract_item">
           
        </div>
        <div class="cContract-item-add">
           <p class="cContract-add-new J_cContract-add"> 
               <span class="cContract-new-plus">+</span>
                添加新的合同所属类型
            </p>
       </div>
       <input type="button" value="提交" class="cContract-item-submit J_cContract_submit" />
    </div>
</form>
    <div class="cContract-list-wrap">
        <div class="cContract-list-box">
            <p class="cContract-box-conword">
                合同:
            </p>
            <ul class="cContract-box-list J_cContract_list">
                @foreach($pactList as $data)
                    <li class="cContract-list-item" pId="{{$data->id}}">{{$data->Name}}</li>
                @endforeach
            </ul>
            <input class="cContract-list-modify J_cContract_modify" type="button" name="" value="修改" />
        </div>
    </div>
</div>
<script>
window.onload = function(){
	//弹窗
	var popup1=new popup({
        width:'400',
        height:'400',
        content:'<div class="cContract-popup-content"><h5>请输入新合同名称</h5><input type="text" class="cContract-content-text J_copy_text"/></div><div class="btn-box"><a class="btn-confirm J_cContract_copyDetermine">确定</a></div>',
        hasMask: true,  //是否显示遮罩层
        enter:'spreadIn',
        leave:'spreadOut'
    });
	var popup2=new popup({
        width:'400',
        height:'400',
        content:'<div class="pop-content"><h5>启用成功!</h5></div><div class="btn-box"><a class="btn-confirm" id="pop_btn_confirm">确定</a></div>',
        hasMask: true,  //是否显示遮罩层
        enter:'spreadIn',
        leave:'spreadOut'
    });
    var popup3=new popup({
        width:'400',
        height:'400',
        content:'<div class="pop-content"><h5>停用成功!</h5></div><div class="btn-box"><a class="btn-confirm" id="pop_btn_confirm">确定</a></div>',
        hasMask: true,  //是否显示遮罩层
        enter:'spreadIn',
        leave:'spreadOut'
    });
    var popup4=new popup({
        width:'400',
        height:'400',
        content:'<div class="pop-content"><h5>操作成功!</h5></div><div class="btn-box"><a class="btn-confirm" id="pop_btn_confirm">确定</a></div>',
        hasMask: true,  //是否显示遮罩层
        enter:'spreadIn',
        leave:'spreadOut'
    });
    var popup5=new popup({
        width:'400',
        height:'400',
        content:'<div class="pop-content"><h5>操作失败!</h5></div><div class="btn-box"><a class="btn-confirm" id="pop_btn_confirm">确定</a></div>',
        hasMask: true,  //是否显示遮罩层
        enter:'spreadIn',
        leave:'spreadOut'
    });
    var popup6=new popup({
        width:'400',
        height:'400',
        content:'<div class="pop-content"><h5>该名字已存在!</h5></div><div class="btn-box"><a class="btn-confirm" id="pop_btn_confirm">确定</a></div>',
        hasMask: true,  //是否显示遮罩层
        enter:'spreadIn',
        leave:'spreadOut'
    });
    var popup7=new popup({
        width:'400',
        height:'400',
        content:'<div class="pop-content"><h5>请选择要修改的合同!</h5></div><div class="btn-box"><a class="btn-confirm" id="pop_btn_confirm">确定</a></div>',
        hasMask: true,  //是否显示遮罩层
        enter:'spreadIn',
        leave:'spreadOut'
    });
   var cContractNo = 0;
   //添加新的合同所属类型
   var addNewContract = function(config) {
       var _self = this;
       _self.config = $.extend({},addNewContract.config,config);
   }
 
   addNewContract.config={
 
   }
 
   addNewContract.prototype={
       _init: function(){
           var _self = this;
       },
       _addCon: function(){
           var _self = this;
           var ubox = '<div class="J_cContract_ubox" inx="666">'+
               '<ul class="cContract-item-list J_item_list">'+
                   '<li class="cContract-list-info cContract-list-index"><!-- 序号 -->'+
                       '<p class="cContract-index-p">'+
                           '序号:'+
                       '</p>'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-indexc"><!-- 序号 -->'+
                       '<a class="cContract-index-up J_index_up"></a>'+
                        '<a class="cContract-index-down J_index_down"></a>'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-job"><!-- 工种 -->'+
                       '<p class="cContract-job-p">'+
                           '工种:'+
                       '</p>'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-jobc"><!-- 工种 -->'+
                       '<select class="cContract-jobc-sel J_jobc_sel">'+
                     '<option value="2">设计</option>'+
                     '<option value="4">开发</option>'+
                     '<option value="6">套餐</option>'+
                  '</select>'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-demand"><!-- 需求类型 -->'+
                       '<p class="cContract-demand-p">'+
                           '需求类型:'+
                       '</p>'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-demandc"><!-- 需求类型 -->'+
                       '<input type="text" class="cContract-demandc-input J_cContract_type" />'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-workTime"><!-- 工时 -->'+
                       '<p class="cContract-workTime-p">'+
                           '工时:'+
                       '</p>'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-workTimec"><!-- 工时 -->'+
                       '<input type="text" class="cContract-workTimec-text J_cContract_workTime J_cContract_time" /> H'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-demandprice"><!-- 需求价格 -->'+
                       '<p class="cContract-demandprice-p J_demandprice_p">'+
                           '需求价格:'+
                       '</p>'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-demandpricec"><!-- 需求价格 -->'+
                       '<input type="text" class="cContract-demandpricec-text J_cContract_demandprice J_cContract_price" /> 元'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-wageprice"><!-- 提成价格 -->'+
                       '<p class="cContract-wageprice-p J_wageprice_p">'+
                           '提成价格:'+
                       '</p>'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-wagepricec"><!-- 提成价格 -->'+
                       '<input type="text" class="cContract-wagepricec-text J_cContract_wageprice J_cContract_price" /> 元'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-move J_cContract_move">'+
                       '删除'+
                   '</li>'+
                   '<li class="cContract-list-info cContract-list-stop J_cContract_stop">'+
                       '停用'+
                   '</li>'+
               '</ul>'+
        '</div>';
           $('.J_index_up:first,.J_index_down:last').css({'opacity': '0','cursor':'default'});
           $('.J_cContract_ubox:first').find('.J_demandprice_p').text('需求价格:');
           $('.J_cContract_ubox:first').find('.J_wageprice_p').text('提成价格:');
           $('.J_index_up,.J_index_down').css({'opacity': '1','cursor':'pointer'});
           $('.J_cContract_item').append(ubox);
           cContractNo = cContractNo+1;
           $('.J_index_up:first,.J_index_down:last').css({'opacity': '0','cursor':'default'});
           $('.J_cContract_ubox').eq(cContractNo-1).find('input').val('').css('border-color','#c9c9c9').removeClass('red');
            $('.J_cContract_special').eq(cContractNo-1).css('display','none');
           _self._selWork();
           $('.J_index_up:last').on('click',function(e){
               _self._up(e);
           });
           $('.J_index_down:last').on('click',function(e){
               _self._down(e);
           });
           var contractSub2 = new contractSub({});
           contractSub2._focusout();
           _self._move();
       },
       _selWork: function(){
       	var uspe = '<ul class="cContract-item-special J_cContract_special"><!-- 选择套餐 -->'+
                '<li class="cContract-list-info cContract-special-webtime"><!-- 前端工时 -->'+
                    '<p class="cContract-webtime-p">'+
                        '工时:'+
                    '</p>'+
                '</li>'+
                '<li class="cContract-list-info cContract-special-webtimec"><!-- 前端工时 -->'+
                    '<input type="text" class="cContract-webtimec-text J_cContract_webtime" /> H'+
                '</li>'+
                '<li class="cContract-list-info cContract-special-webprice"><!-- 前端价格 -->'+
                    '<p class="cContract-webprice-p">'+
                        '前端价格:'+
                    '</p>'+
                '</li>'+
                '<li class="cContract-list-info cContract-special-webpricec"><!-- 前端价格 -->'+
                    '<input type="text" class="cContract-webpricec-text J_cContract_webprice" /> 元'+
                '</li>'+
                '<li class="cContract-list-info cContract-special-webwage"><!-- 前端提成 -->'+
                    '<p class="cContract-webwage-p">'+
                        '前端提成:'+
                    '</p>'+
                '</li>'+
                '<li class="cContract-list-info cContract-special-webwagec"><!-- 前端提成 -->'+
                   '<input type="text" class="cContract-webwagec-text J_cContract_webwage" /> 元'+
                '</li>'+
            '</ul>';
           $('.J_jobc_sel').on('change',function(e){
               var target=e.target;
               var parent=$(target).parent().parent();
               if($(target).val()=='6'){
                   $(parent).find('.J_demandprice_p').text('视觉价格:');
                   $(parent).find('.J_wageprice_p').text('视觉提成:');
                   $(parent).parent().find('.J_cContract_special').remove();
                   $(parent).parent().append(uspe).find('.J_cContract_webprice,.J_cContract_webwage').addClass('J_cContract_price'); 
                   $(parent).parent().find('.J_cContract_webtime').addClass('J_cContract_time');
               }
               else{
                   $(parent).find('.J_demandprice_p').text('需求价格:');
                   $(parent).find('.J_wageprice_p').text('提成价格:');
                   $(parent).parent().find('.J_cContract_special').remove();
               }
           });
       },
       _up: function(e){
       		var _self = this;
           var target=e.target;
           var parent=$(target).parents('.J_cContract_ubox');
           if($(parent).index()>0){
               var prev = $(parent).prev();
               var now = $(parent);
               var inxup = now.attr('pacttypeid');
               var inxdown = prev.attr('pacttypeid');
               now.insertBefore(prev);
               _self._sort(inxup,inxdown);
           }
           else{
               return 0;
           }
           $('.J_index_up,.J_index_down').css({'opacity': '1','cursor':'pointer'});
           $('.J_index_up:first,.J_index_down:last').css({'opacity': '0','cursor':'default'});
       },
       _down: function(e){
       		var _self = this;
           var target=e.target;
           var parent=$(target).parents('.J_cContract_ubox');
           var len=$('.J_cContract_ubox').length;
           if($(parent).index()<len-1){
               var next = $(parent).next();
               var now = $(parent);
               var inxdown = now.attr('pacttypeid');
               var inxup = next.attr('pacttypeid');
               now.insertAfter(next);
               _self._sort(inxup,inxdown);
           }
           else{
               return 0;
           }
           $('.J_index_up,.J_index_down').css({'opacity': '1','cursor':'pointer'});
           $('.J_index_up:first,.J_index_down:last').css({'opacity': '0','cursor':'default'});
       },
       _sort: function(upId,downId){
           $.ajax({
               url: 'sort',
               type: 'post',
               data:{
                   up_id : upId,
                   down_id: downId,
                   _token: '{{csrf_token()}}'
               },
               success:function(data){
                   
               }
           })
       },
       _move: function(){
           var _self =this;
           $('.J_cContract_move').on('click',function(e){
               var target = e.target;
               var parent = $(target).parents('.J_cContract_ubox');
               $(parent).remove();
               $('.J_index_up,.J_index_down').css({'opacity': '1','cursor':'pointer'});
               $('.J_index_up:first,.J_index_down:last').css({'opacity': '0','cursor':'default'});
           })
       }
 
   }
   var addNewContract1 = new addNewContract({
 
   });
   $('.J_cContract-add').on('click',function(){
       addNewContract1._addCon();
   })
 
 
   //提交
   var contractSub = function(config){
       var _self = this;
       _self.config = $.extend({},contractSub.config,config);
   }
   contractSub.config={
       regDate: /([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))/,//日期正则
       regPNZInteger: /^[1-9]\d*$/,//验证非零的正整数
       regPRNTDecimals: /^[0-9]+(\.[0-9]{2})?$/,//验证有两位小数的正实数
       conName: '',
       date: '',
       demandType: '',
       workTime: '',
       price: '',
       data: '',
       modifyD: ''
   }
   contractSub.prototype={
       _init: function(){
           var _self = this;
       },
       _testVal1: function(inputval){
         var _self=this;
         if (inputval=='') {
            return false;
         }
         else if (inputval.length>20) {
            return false;
         }
         else {
            return true;
         }
      },
      _testVal2: function(inputval){
         var _self=this;
         if (inputval>127) {
            return false;
         }
         else if(inputval !=''){
             if(inputval != 0){
                 if(!_self.config.regPNZInteger.test(inputval)){
                   return false;
                }
                else{
 
                    return true;
                }
            }
            else {
                return true;
            }
         }
         else {
            return true;
         }
      },
      _testVal3: function(inputval){
           var _self=this;
           if (inputval.length>15) {
               return false;
           }
           else if(inputval == ''){
                   return false;
           }
           else if(!_self.config.regPRNTDecimals.test(inputval)){
               return false;
           }
           else {
               return true;
           }
      },
      _testVal4: function(inputval){
            var _self=this;
            if(inputval !=''){
                if(!_self.config.regDate.test(inputval)){
                       return false;
                }
                else{
 
                 return true;
                 }
            }
            else {
               return true;
            }
      },
      _data: function(){
          var _self = this;
          var ai=0;
          var name = $('.J_cContract_name').val();
          function getUtf8Length(str){
               if (str==""||str==null) 
                   return 0;
               var n = 0;
               len = 0;
               for (i = 0; i < str.length; i++) {
                   n = str.charCodeAt(i);
                   if (n <= 255) 
                       len += 1;
                   else
                       len += 3;
               }
               return len;
           }
         var unamelength = getUtf8Length(name);
 
          if($('.J_cContract_date').eq(0).val() && $('.J_cContract_date').eq(1).val()){
              var validity = $('.J_cContract_date').eq(0).val()+','+$('.J_cContract_date').eq(1).val();
          }
          else{
              var validity = '';
          }
          var lens = $('.J_cContract_ubox').length;
           var pactTypei = '';
           var typeadd = '';
          $('.J_cContract_ubox').each(function(i,v){
              var pactTypes = new Array();
              var t = $(v).find('.J_jobc_sel').val();
              var ii;
              var pactTypeii;
              if(t == 6){
                  ii=8;
                  pactTypes[0] = '6';
                  pactTypes[1] = $(v).find('.J_cContract_type').val();
                  pactTypes[2] = $(v).find('.J_cContract_workTime').val();
                  pactTypes[3] = $(v).find('.J_cContract_demandprice').val();
                  pactTypes[4] = $(v).find('.J_cContract_wageprice ').val();
                  pactTypes[5] = $(v).find('.J_cContract_webtime').val();
                  pactTypes[6] = $(v).find('.J_cContract_webprice').val();
                  pactTypes[7] = $(v).find('.J_cContract_webwage').val();
                  pactTypeii = '{i:0;s:'+ pactTypes[0].length +':"'+ pactTypes[0] +'";i:1;s:'+ getUtf8Length(pactTypes[1]) +':"'+ pactTypes[1] +'";i:2;s:'+ pactTypes[2].length +':"'+ pactTypes[2] +'";i:3;s:'+ pactTypes[3].length +':"'+ pactTypes[3] +'";i:4;s:'+ pactTypes[4].length +':"'+ pactTypes[4] +'";i:5;s:'+ pactTypes[5].length +':"'+ pactTypes[5] +'";i:6;s:'+ pactTypes[6].length +':"'+ pactTypes[6] +'";i:7;s:'+ pactTypes[7].length +':"'+ pactTypes[7] +'";}';
              }
              else if(t == 4){
                  ii=5;
                  pactTypes[0] = '4';
                  pactTypes[1] = $(v).find('.J_cContract_type').val();
                  pactTypes[2] = $(v).find('.J_cContract_workTime').val();
                  pactTypes[3] = $(v).find('.J_cContract_demandprice').val();
                  pactTypes[4] = $(v).find('.J_cContract_wageprice ').val();
                  pactTypeii = '{i:0;s:'+ pactTypes[0].length +':"'+ pactTypes[0] +'";i:1;s:'+ getUtf8Length(pactTypes[1]) +':"'+ pactTypes[1] +'";i:2;s:'+ pactTypes[2].length +':"'+ pactTypes[2] +'";i:3;s:'+ pactTypes[3].length +':"'+ pactTypes[3] +'";i:4;s:'+ pactTypes[4].length +':"'+ pactTypes[4] +'";}';
              }
              else{
                  ii=5;
                  pactTypes[0] = '2';
                  pactTypes[1] = $(v).find('.J_cContract_type').val();
                  pactTypes[2] = $(v).find('.J_cContract_workTime').val();
                  pactTypes[3] = $(v).find('.J_cContract_demandprice').val();
                  pactTypes[4] = $(v).find('.J_cContract_wageprice ').val();
                  pactTypeii = '{i:0;s:'+ pactTypes[0].length +':"'+ pactTypes[0] +'";i:1;s:'+ getUtf8Length(pactTypes[1]) +':"'+ pactTypes[1] +'";i:2;s:'+ pactTypes[2].length +':"'+ pactTypes[2] +'";i:3;s:'+ pactTypes[3].length +':"'+ pactTypes[3] +'";i:4;s:'+ pactTypes[4].length +':"'+ pactTypes[4] +'";}';
              }
              if(typeof($(v).attr('pacttypeid'))=="undefined"){
              		if(typeof($(v).parent().parent().children().attr('id'))=="undefined"){
              			pactTypei = pactTypei +'i:'+ i +';a:'+ ii +':'+ pactTypeii;
              		}
              		else{
              			typeadd = typeadd + 'i:'+ ai +';a:' + ii +':'+ pactTypeii;
              			ai++;
              		}
	          	}
	          	else{
	          		var id = $(v).attr('pacttypeid');
	          		pactTypei = pactTypei +'i:'+ id +';a:'+ ii +':'+ pactTypeii;
	          	}
          })
			if(typeof($('.J_cContract_nametime').attr('id'))=="undefined")
			{
				_self.config.data = 'a:2:{s:4:"Pact";a:2:{s:4:"Name";s:'+ unamelength +':"'+ name +'";s:8:"Validity";s:'+ validity.length +':"'+ validity +'";}s:8:"PactType";a:'+ lens +':{' + pactTypei + '}}';
			}
			else{
				_self.config.data = 'a:3:{s:4:"Pact";a:2:{s:4:"Name";s:'+ unamelength +':"'+ name +'";s:8:"Validity";s:'+ validity.length +':"'+ validity +'";}s:8:"PactType";a:'+ (lens-ai) +':{' + pactTypei + '}s:7:"TypeAdd";a:'+ ai +':{'+ typeadd +'}}';
				
			}

           //_self.config.modifyD = 'a:2:{s:4:"Pact";a:2:{s:4:"Name";s:'+ unamelength +':"'+ name +'";s:8:"Validity";s:'+ validity.length +':"'+ validity +'";}s:8:"PactType";i:'+id+';a:'+ lens +':{' + pactTypei + '}}';
      },
      _focusout: function(){
          var _self = this;
          $('input').on('focusout',function(){
              _self.config.conName = $.trim($('.J_cContract_name').val());
                if (_self._testVal1(_self.config.conName)==true) {
                   $('.J_cContract_name').css('border-color','#c9c9c9').removeClass('red');
                }
                else{
                    $('.J_cContract_name').css('border-color','red').addClass('red');
                }
                $('.J_cContract_type').each(function(i,v){
                  _self.config.demandType = $.trim($(v).val());
                  if (_self._testVal1(_self.config.demandType)==true) {
                     $(v).css('border-color','#c9c9c9').removeClass('red');
                  }
                  else{
                      $(v).css('border-color','red').addClass('red');
                  }
                })
                $('.J_cContract_date').each(function(i,v){
                    _self.config.date = $.trim($(v).val());
                    if (_self._testVal4(_self.config.date)==true) {
                   $(v).css('border-color','#c9c9c9').removeClass('red');
                }
                else{
                    $(v).css('border-color','red').addClass('red');
                }
                })
                $('.J_cContract_time').each(function(i,v){
                    _self.config.workTime = $.trim($(v).val());
                    if (_self._testVal2(_self.config.workTime)==true) {
                   $(v).css('border-color','#c9c9c9').removeClass('red');
                }
                else{
                    $(v).css('border-color','red').addClass('red');
                }
                })
                $('.J_cContract_price').each(function(i,v){
                    _self.config.price = $.trim($(v).val());
                    if (_self._testVal3(_self.config.price)==true) {
                   $(v).css('border-color','#c9c9c9').removeClass('red');
                }
                else{
                    $(v).css('border-color','red').addClass('red');
                }
                })
                $('.J_cContract_wageprice').each(function(i,v){
                    var wprice = $.trim($(v).val());
                    var dprice = $.trim($(v).parents('.J_item_list').find('.J_cContract_demandprice').val());
                    if(wprice-dprice<=0 && wprice!=''){
                        $(v).css('border-color','#c9c9c9').removeClass('red');
                    }
                   else{
                       $(v).css('border-color','red').addClass('red');
                   }
               })
               $('.J_cContract_webwage').each(function(i,v){
                    var wprice = $.trim($(v).val());
                    var dprice = $.trim($(v).parents('.J_cContract_special').find('.J_cContract_webprice').val());
                    if(wprice-dprice<=0 && wprice!=''){
                        $(v).css('border-color','#c9c9c9').removeClass('red');
                    }
                   else{
                       $(v).css('border-color','red').addClass('red');
                   }
               })
          })
      },
      _formSub: function(){
          var _self=this;
         $('.J_cContract_submit').click(function(){
             _self._data();
                if($('.red').length==0 && $.trim($('.J_cContract_name').val()).length>0){
                    $('.J_cContract_form').val(_self.config.data);
                    $('#J_cContract_form').submit();
                    
                }
                else{
                    popup5.create();
                }
         })
         /*$(document).keydown(function(e){
            if(e.keyCode == 13){
            	if($('#pop_close').length == 0){
            		$('.J_cContract_submit').click();
            	}
                else if($('#pop_close').length == 1){
            		$('#pop_btn_confirm').click();
                }
            }
         })*/
      }
   }
 	if('{{session('callback')}}' == '添加成功'){
    	popup4.create();
    }
    else if('{{session('callback')}}' == '合同名重复'){
    	popup6.create();
    }
    else if('{{session('callback')}}' == '修改成功'){
		popup4.create();
    }
   var contractSub1 = new contractSub({});
   contractSub1._formSub();
 
   var stopB = '<input type="button" value="停用" class="cContract-item-stopB J_cContract_cStop" />';
   var addB = '<input type="button" value="添加合同" class="cContract-item-stopB J_cContract_cAdd" />';
   var copyB = '<input type="button" value="复制合同" class="cContract-item-stopB J_cContract_cCopy" />';
 
   //修改
   var contractModify = function(config){
       var _self = this;
       _self.config = $.extend({},contractModify.config,config);
   }
 
   contractModify.config = {
       pId : '',
       del : '',
       cDel: '',
       pacttypeId :  ''
   }
 
   contractModify.prototype = {
       _init : function(){
           var _self = this;
 
       },
       _modify : function(){
           var _self = this;
           _self._choose();
           $('.J_cContract_modify').on('click',function(){
               if($('.ccContract-list-cur').length>0){
               		$('#J_cContract_form').attr('action','/system/cContract/edit_form');
                   
                   $('.red').css('border-color','#c9c9c9').removeClass('red');
                   _self._edit();
               }
               else{
                   popup7.create();
                   $('#pop_btn_confirm').on('click',function(){
			    		$('#pop_box,#pop_mask').remove();
			    	})
               }
           });
       },
       _choose : function(){
           var _self = this;
           $('.cContract-list-item').on('click',function(e){
               var target = e.target;
               $(target).addClass('ccContract-list-cur').siblings().removeClass('ccContract-list-cur');
               _self.config.pId = $(target).attr('pid');
           })
       },
       _stop : function(delType,del,id,obj){
           var _self = this;
           $.ajax({
                url: 'destroy',
                type: 'post',
                data: {
                    del_type : delType,
                    del : del,
                    pacttype_id : id,
                    pact_id : id,
                    _token : '{{csrf_token()}}'
                },
                success:function(data){
                    var target = obj.target;
                    if(delType == 0 && del == 1){
                        var parents = $(target).parents('.J_cContract_ubox');
                        $(target).text('启用');
                        $(parents).attr('del',0);
                        popup3.create();
                    }
                    else if(delType == 0 && del == 0){
                        var parents = $(target).parents('.J_cContract_ubox');
                       $(target).text('停用');
                       $(parents).attr('del',1);
                       popup2.create();
                    }
                    else if(delType == 1 && del == 1){
                        var parent = $(target).parent().find('.J_cContract_nametime');
                        $(target).val('启用');
                        $(parent).attr('del',0);
                        _self.config.cDel = 0;
                        popup3.create();
                    }
                    else if(delType == 1 && del == 0){
                        var parent = $(target).parent().find('.J_cContract_nametime');
                        $(target).val('停用');
                       $(parent).attr('del',1);
                       _self.config.cDel = 1;
                       popup2.create();
                    }
                }
            })
       },
       _edit : function(){
           var _self = this;
           $.ajax({
                url: 'edit',
                type: 'post',
                data: {
                    pact_id:_self.config.pId,
                    _token : '{{csrf_token()}}'
                },
                success:function(data){
                    var list=JSON.parse(data);
                    var pact = list.Pact;
                    var ptype = list.PactType;
                    $('.J_cContract_pid').val(pact[0].id);
                    $('.J_cContract_nametime').attr({'id':pact[0].id,'del':pact[0].Del});
                    _self.config.cDel = pact[0].Del;
                    if(pact[0].Del == 1){
                        $('.J_cContract_cStop').val('停用');
                    }
                    else{
                       $('.J_cContract_cStop').val('启用');
                    }
                    $('.J_cContract_item').empty();
                    $('.J_cContract_name').val(pact[0].Name);
                    var validity = pact[0].Validity;
                    var validityArray = validity.split(',');
                   $('.J_time_start').val(validityArray[0]);
                   $('.J_time_end').val(validityArray[1]);
                    for (var i = 0; i <ptype.length; i++) {
                        addNewContract1._addCon();
                        if(ptype[i].Del == 1){
                            $('.J_cContract_stop:last').text('停用');
                        }
                        else{
                            $('.J_cContract_stop:last').text('启用');
                        }
                        $('.J_cContract_move').hide();
                        $('.J_cContract_stop').css('display','table-cell');
                        $('.J_cContract_ubox:last').attr({'pacttypeId':ptype[i].id,'del':ptype[i].Del,'inx':ptype[i].Inx});
                        $('.J_jobc_sel:last').val(ptype[i].Type).change();
                        $('.J_cContract_type:last').val(ptype[i].Name);
                        if(ptype[i].Type==2){
                            $('.J_cContract_workTime:last').val(ptype[i].UedWorktime);
                            $('.J_cContract_demandprice:last').val(ptype[i].UedPrice);
                            $('.J_cContract_wageprice:last').val(ptype[i].UedCommission);
                        }
                        else if(ptype[i].Type==4){
                            $('.J_cContract_workTime:last').val(ptype[i].KWorktime);
                            $('.J_cContract_demandprice:last').val(ptype[i].KPrice);
                            $('.J_cContract_wageprice:last').val(ptype[i].KCommission);
                        }
                        else{
                            $('.J_cContract_workTime:last').val(ptype[i].UedWorktime);
                            $('.J_cContract_demandprice:last').val(ptype[i].UedPrice);
                            $('.J_cContract_wageprice:last').val(ptype[i].UedCommission);
                            $('.J_cContract_webtime:last').val(ptype[i].KWorktime);
                            $('.J_cContract_webprice:last').val(ptype[i].KPrice);
                            $('.J_cContract_webwage:last').val(ptype[i].KCommission);
                        }
                    }
                    $('.J_cContract_stop').on('click',function(e){
                        var target = e.target;
                        var parents = $(target).parents('.J_cContract_ubox');
                        _self.config.del = parseInt($(parents).attr('del'));
                        _self.config.pacttypeId = parseInt($(parents).attr('pacttypeId'))
                        if(_self.config.cDel == 0 && _self.config.del == 0){
                            popup5.create();
                        }    
                        else if(_self.config.cDel == 0 && _self.config.del == 1){
                            popup5.create();
                        }
                        else{
                            _self._stop(0,_self.config.del,_self.config.pacttypeId,e);
                        }
                    });
 					$('.J_cContract_cStop,.J_cContract_cAdd,.J_cContract_cCopy').remove();
                   $('.J_cContract_submit').after(copyB,stopB,addB);
                   $('.J_cContract_cAdd').on('click',function(){
                   	   $('#J_cContract_form').attr('action','/system/cContract/create');
                       $('.J_cContract_cStop,.J_cContract_cAdd,.J_cContract_cCopy').remove();
                       $('.J_cContract_item').empty();
                       $('.J_cContract_nametime input').val('');
                       $('.J_cContract_nametime').removeAttr('id').removeAttr('del');
                       $('.red').css('border-color','#c9c9c9').removeClass('red');
                   });
                   $('.J_cContract_cStop').on('click',function(e){
                       var d = $('.J_cContract_nametime').attr('del');
                       var id = $('.J_cContract_nametime').attr('id');
                       _self._stop(1,d,id,e);
                   });
                   $('.J_cContract_cCopy').on('click',function(){
                   		popup1.create();
                   		var pactName = $('.J_copy_text').val();
                   		var pactModId = pact[0].id;
                   		$('.J_copy_text').on('focusout',function(){
           					if(pactName == ' '){
           						$('.J_copy_text').css('border-color','red').addClass('red');
           					}
           					else{
               					$('.J_copy_text').css('border-color','#c9c9c9').removeClass('red');
               				}
           				})
                   		$('.J_cContract_copyDetermine').on('click',function(){
                   			if($('.red').length==0 && $.trim($('.J_copy_text').val()).length>0){
                   				pactName = $('.J_copy_text').val();
                   				$('#pop_box,#pop_mask').remove();
                   				_self._copy(pactName,pactModId);
                   			}
                   			else{
                   				return 0;
                   			}
                   		})
                   });
                }
            })
       },
       _copy : function(pactName,pactModId){
       		var _self = this;
       		$.ajax({
       			url: 'copy',
                type: 'post',
                data: {
                    pact_name: pactName,
                    pact_mod_id : pactModId,
                    _token : '{{csrf_token()}}'
                },
                success:function(data){
                	var list = JSON.parse(data);
                	var l = list.pact_list.length;
                	var liLast = list.pact_list[l-1];
                	var str = '<li class="cContract-list-item" pId="'+ liLast.id +'">'+ liLast.Name +'</li>';
                	$('.J_cContract_list').append(str);
                	$('.cContract-list-item').on('click',function(e){
			               var target = e.target;
			               $(target).addClass('ccContract-list-cur').siblings().removeClass('ccContract-list-cur');
			               _self.config.pId = $(target).attr('pid');
			           })
                	$('.cContract-list-item:last').click();
                	$('.J_cContract_name').val(liLast.Name);
       			}
       		})
       }
   }
   var contractModify1 = new contractModify({});
   contractModify1._modify();
 
}
</script>
@endsection
